package server.layer;

import java.io.InputStreamReader;
import java.net.Socket;
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: Awake
 * Date: 22.04.12
 * Time: 18:39
 * To change this template use File | Settings | File Templates.
 */
public class ServerThread implements Runnable {
    private Socket clSocket;
    static ServiceServer server;
    private boolean start = true;
    String bye = "{\"command\":\".bye\"}";

    public ServerThread(Socket clientSocket, ServiceServer server) {
        this.server = server;
        clSocket = clientSocket;
    }

    @Override
    public void run() {

        try {
            while (start) {
                Scanner in = new Scanner(new InputStreamReader(clSocket.getInputStream()));
                String getStr = "";
                getStr = in.nextLine();
                System.out.println("[from " + clSocket.hashCode() + "] : " + getStr);
                ServiceHandler handler = new ServiceHandler();
                handler.receive(getStr, clSocket);
                start = !bye.equals(getStr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
